package com.totoro.tymapping.enums;

import com.totoro.tymapping.constants.ConditionConst;
import com.totoro.tymapping.executor.condition.ConditionExecutor;
import com.totoro.tymapping.executor.condition.impl.NameExecutor;
import com.totoro.tymapping.executor.condition.impl.NotPermissionExecutor;
import com.totoro.tymapping.executor.condition.impl.PapiExecutor;
import com.totoro.tymapping.executor.condition.impl.PermissionExecutor;

/**
 * @author Totoro
 * @version 0.1.0
 * @date 2025/8/13 - 15:47
 * @description 条件执行器枚举
 **/
public enum ConditionExecutorEnum {
    NAME(ConditionConst.NAME, new NameExecutor()),
    PERMISSION(ConditionConst.PERMISSION, new PermissionExecutor()),
    NOT_PERMISSION(ConditionConst.NOT_PERMISSION, new NotPermissionExecutor()),
    PAPI(ConditionConst.PAPI, new PapiExecutor());

    private String conditionType;
    private ConditionExecutor conditionExecutor;

    ConditionExecutorEnum(String conditionType, ConditionExecutor conditionExecutor) {
        this.conditionType = conditionType;
        this.conditionExecutor = conditionExecutor;
    }

    public static ConditionExecutor getConditionExecutor(String condition) {
        for (ConditionExecutorEnum value : values()) {
            if (condition.startsWith(value.conditionType)) {
                return value.conditionExecutor;
            }
        }
        return null;
    }
}
